 let currentYear = new Date().getFullYear();
    let currentMonth = new Date().getMonth() + 1;

    function generateCalendar(year, month) {
      const firstDay = new Date(year, month - 1, 1);
      const lastDay = new Date(year, month, 0);
      const daysInMonth = lastDay.getDate();
      const startDayOfWeek = firstDay.getDay();

      const calendarBody = document.getElementById('calendar-body');
      calendarBody.innerHTML = '';

      let row = document.createElement('tr');

      // 添加前一个月的剩余天数
      for (let i = 0; i < startDayOfWeek; i++) {
        row.appendChild(document.createElement('td'));
      }

      // 添加本月的天数
      for (let day = 1; day <= daysInMonth; day++) {
        const cell = document.createElement('td');
        cell.textContent = day;

        if (day === new Date().getDate() && year === new Date().getFullYear() && month === new Date().getMonth() + 1) {
          cell.classList.add('selected-date');
        }

        row.appendChild(cell);

        // 如果当前列是星期六，则开始新的一行
        if ((startDayOfWeek + day) % 7 === 0) {
          calendarBody.appendChild(row);
          row = document.createElement('tr');
        }
      }

      // 添加下个月的开始天数
      while (row.children.length < 7) {
        row.appendChild(document.createElement('td'));
      }

      if (row.children.length > 0) {
        calendarBody.appendChild(row);
      }

      document.getElementById('month-year').textContent = `${year}年${month}月`;
    }

    function previousMonth() {
      if (currentMonth === 1) {
        currentYear--;
        currentMonth = 12;
      } else {
        currentMonth--;
      }
      generateCalendar(currentYear, currentMonth);
    }

    function nextMonth() {
      if (currentMonth === 12) {
        currentYear++;
        currentMonth = 1;
      } else {
        currentMonth++;
      }
      generateCalendar(currentYear, currentMonth);
    }

    // 初始化当前月份的日历
    generateCalendar(currentYear, currentMonth);